{% extends 'base.html' %}
{% load static %}
{% block title %}
    用户管理
{% endblock %}
{% block header_name %}
    用户管理
{% endblock %}
{% block bread %}
      <!-- Breadcrumb-->
    <div class="breadcrumb-holder container-fluid">
    <ul class="breadcrumb">
      <li class="breadcrumb-item"><a href="{% url 'index' %}">首页</a></li>
      <li class="breadcrumb-item active">用户管理</li>
    </ul>
    </div>
{% endblock %}
{% block body %}


    <section class="tables">
      <div class="container-fluid">
        <div class="row">
          <div class="col-lg-12">
            <h1>共有{{ count }}名管理员</h1>
            <div class="card">
              <div class="card-header">
                <div class="btn-group">
                <button type="button" class="btn btn-info dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                  筛选学院
                </button>
                <div class="dropdown-menu">
                <a class="dropdown-item" href="{% url 'users:admins' %}">全部</a>
                  {% for academy in academy_list %}
                    <a class="dropdown-item" href="?academy={{ academy }}" id="auto-select-academy">{{ academy }}</a>
                  {% endfor %}
                </div>
              </div>

              </div>
              <div class="card-body">

                <div class="table-responsive">
                  <table id="adminTable" class="table table-striped table-hover table-bordered">
                    <thead>
                      <tr>
                        <th>姓名</th>
                        <th>邮箱</th>
                        <th>学院</th>
                        <th>年级</th>
                        <th>班级</th>
                        <th>上次登录</th>
                        <th>权限</th>
                        <th>操作</th>
                      </tr>
                    </thead>
                    <tbody>
                    {% with role=request.user.role %}
                      {% for admin in admins %}
                          <tr>
                          <td>{{ admin.name }}</td>
                          <td>{{ admin.email }}</td>
                          <td>{% if admin.academy %}{{ admin.academy }}{% else %}-{% endif %}</td>
                          <td>{% if admin.grade %}{{ admin.grade }}{% else %}-{% endif %}</td>
                          <td>{% if admin.klass %}{{ admin.klass }}{% else %}-{% endif %}</td>
                          <td>{% if admin.last_login %}{{ admin.last_login }}{% else %}-{% endif %}</td>
                          <td>{{ admin.get_role_display }}</td>
                          <td>
                            {% if role == 1 or role == 2 %}
{#                              <a href="{% url 'users:admin_detail' admin.pk %}" class="btn btn-primary btn-sm">查看</a>#}
                              <a href="{% url 'users:update_profile' admin.pk %}" class="btn btn-warning btn-sm"><i class="fa fa-edit"></i>编辑</a>
                              <a href="{% url 'users:admin_delete' admin.pk %}" class="btn btn-danger btn-sm"><i class="fa fa-eraser"></i>删除</a>
                            {% endif %}
                          </td>
                          </tr>
                      {% endfor %}
                    {% endwith %}
                    </tbody>
                  </table>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </section>

    {% include 'pagination.html' %}
{% endblock %}
{% block js %}
  <script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/bootstrap-table.min.js"></script>
  <script src="https://cdn.bootcss.com/bootstrap-table/1.15.4/extensions/resizable/bootstrap-table-resizable.min.js"></script>
  <script src="{% static 'js/colResizable-1.6.min.js' %}"></script>
  <script>
    $(function () {
        $("#adminTable").colResizable({
          liveDrag: true,//实时显示滑动位置
          gripInnerHtml: "<div class='grip'></div>",
          draggingClass: "dragging",
          postbackSafe: true,//刷新后保留之前的拖拽宽度
          headerOnly:true,
          resizeMode:"overflow",
          //onResize: onSampleResized
        });


        function getQueryVariable(variable) {
          var query = window.location.search.substring(1);
          var vars = query.split("&");
          for (var i=0;i<vars.length;i++) {
            var pair = vars[i].split("=");
            if(pair[0] == variable){return pair[1];}
          }
          return false;
        }
        var concatQuery = "";
        var academy = getQueryVariable("academy");
        if (academy) {
        concatQuery = "academy=" + academy;
        }
        $('.page-link').each(function () {
          // 分页时携带参数
          var oldHref = $(this).attr("href");
          newHref = oldHref + "&" + concatQuery;
          $(this).attr("href", newHref);
        });
    })
  </script>
{% endblock %}
